<?php


namespace App\Exceptions;


use Symfony\Component\HttpKernel\Exception\HttpException;

class CustomException extends HttpException
{
    protected $message;
    protected $code;

    public function __construct(int $errorCode, int $statusCode = 200)
    {
        $this->parseError($errorCode);
        parent::__construct($statusCode, $this->message);
    }

    public function parseError($errorCode)
    {
        $errorCodes = [
            1 => [
                'msg' => '系统错误',
                'code' => 'system.error'
            ],
            400 => [
                'msg' => '',
                'code' => ''
            ]
        ];
        $error = $errorCodes[$errorCode] ?? $errorCodes[1];
        $this->message = $error['msg'];
        $this->code = $error['code'];
    }
}